<template>
  <div class="scroll-container" ref="scrollContainer" @wheel.prevent="handleScroll">
    <scroll ref="scroll">
      <div class="scroll-wrapper" ref="myNavBar" :style="{left: left + 'px'}">
        <slot></slot>
      </div>
    </scroll>
  </div>
</template>

<script>
import Scroll from '../scroll/index'
export default {
  name: 'scrollPane',
  data() {
    return {
      left: 0
    }
  },
  components: {
    Scroll
  },
  mounted() {
    this.moveToTarget()
    setTimeout(() => {
      this.$refs.scroll.refresh()
    }, 200)
  },
  methods: {
    moveToTarget($target) {
      // this.$refs.scroll.scrollToElement(this.$refs.tag[index], 200, true)
      if (!this.$refs.myNavBar) {
        return
      }
      let items = this.$refs.myNavBar.children
      let width = 0
      for (let i = 0; i < items.length; i++) {
        width += items[i].clientWidth
      }
      this.$refs.myNavBar.style.width = `${width}px`
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.scroll-container {
  width: 100%;
}
</style>
